package com.saihai.jiankang.jkUser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.saihai.jiankang.jkUser.domain.JkUser;
import com.saihai.jiankang.jkUser.service.IJkUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.saihai.common.annotation.Log;
import com.saihai.common.core.controller.BaseController;
import com.saihai.common.core.domain.AjaxResult;
import com.saihai.common.enums.BusinessType;

import com.saihai.common.utils.poi.ExcelUtil;
import com.saihai.common.core.page.TableDataInfo;

/**
 * 健康微信用户Controller
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/jk/user")
public class JkUserController extends BaseController
{
    @Autowired
    private IJkUserService jkUserService;

    /**
     * 查询健康微信用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JkUser jkUser)
    {
        startPage();
        List<JkUser> list = jkUserService.selectJkUserList(jkUser);
        return getDataTable(list);
    }



    /**
     * 导出健康微信用户列表
     */
    @Log(title = "健康微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkUser jkUser)
    {
        List<JkUser> list = jkUserService.selectJkUserList(jkUser);
        ExcelUtil<JkUser> util = new ExcelUtil<JkUser>(JkUser.class);
        util.exportExcel(response, list, "健康微信用户数据");
    }

    /**
     * 获取健康微信用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jkUserService.selectJkUserById(id));
    }

    /**
     * 新增健康微信用户
     */
    @Log(title = "健康微信用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JkUser jkUser)
    {
        int i = jkUserService.insertJkUser(jkUser);
        if(i>0) {
            return AjaxResult.success("新增成功",jkUser);
        }else {
            return AjaxResult.error("新增失败！");
        }
    }

    /**
     * 修改健康微信用户
     */
    @Log(title = "健康微信用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkUser jkUser)
    {
        return toAjax(jkUserService.updateJkUser(jkUser));
    }

    /**
     * 删除健康微信用户
     */
    @Log(title = "健康微信用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jkUserService.deleteJkUserByIds(ids));
    }
}
